var GameBase = require('geoGameBase');
var UIStartDialog = require('geoUIStartDialog');

cc.Class({
    extends: GameBase,

    properties: {
        gameTitle:'游戏标题',
        gameDesc:'游戏介绍',
        startDialogPrefab:{
            default:null,
            type:cc.Prefab,
        },
        startDialogContainer:{
            default:null,
            type:cc.Node,
        },
        titleVoice:{
            default:null,
            type:cc.AudioClip,
            tooltip:'游戏标题语音'
        },
        playScene:{
            default:null,
            type:cc.SceneAsset,
            tooltip:'游戏场景'
        },
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        // 创建开始对话框
        var dlgNode = cc.instantiate(this.startDialogPrefab);
        this.startDialogContainer = this.startDialogContainer || cc.director.getScene().getComponentInChildren(cc.Canvas).node;
        this.startDialogContainer.addChild(dlgNode);
        // 获取对话框组件
        var dlg = dlgNode.getComponent(UIStartDialog);
        // 设置标题和描述
        dlg.setTitle(this.gameTitle);
        dlg.setDesc(this.gameDesc);
        // 设置回调
        dlg.setStartButtonCallback(this.startGame.bind(this));
        dlg.setCloseButtonCallback(this.closeGame.bind(this));
    },
    start(){
        if (this.titleVoice){
            this.audio.playVoice(this.titleVoice, false, 1);
        }
    },
    startGame(){
        cc.log('start game...');
        cc.director.loadScene(this.playScene.name);
    },
    closeGame(){
        cc.log('close game...');
    }

    // update (dt) {},
});